package com.xinruke.hostels.central.manage.service;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.xinruke.hostels.cache.extract.extractor.DictInfoCacheExtractor;
import com.xinruke.hostels.central.manage.interfaces.dto.*;
import com.xinruke.hostels.central.manage.mapper.YwJiudianMapper;
import com.xinruke.hostels.central.manage.mapper.YwJiudianMeetingMapper;
import com.xinruke.hostels.common.cache.ManageUserCache;
import com.xinruke.hostels.common.constants.SysDicConstant;
import com.xinruke.hostels.common.exception.ArgumentException;
import com.xinruke.hostels.common.exception.ServerException;
import com.xinruke.hostels.common.mybatis.MyExample;
import com.xinruke.hostels.common.po.XtYewuyonghu;
import com.xinruke.hostels.common.po.YwJiudian;
import com.xinruke.hostels.common.po.constants.YwFangjianLeixingConstants;
import com.xinruke.hostels.common.util.MD5Util;
import com.xinruke.hostels.common.util.StringUtil;
import com.xinruke.hostels.common.vo.ResultVO;
import com.xinruke.hostels.common.vo.query.EConditionOperator;
import com.xinruke.hostels.common.vo.query.OrderField;
import com.xinruke.hostels.common.vo.query.QueryConditions;
import com.xinruke.hostels.common.vo.query.RowsDataVO;
import com.xinruke.hostels.dailymanage.interfaces.enums.ECommentScoreDescribe;
import com.xinruke.hostels.manage.user.interfaces.api.ManageUserApi;
import com.xinruke.hostels.manage.user.interfaces.dto.UserInfoAddDefaultDTO;
import com.xinruke.hostels.support.interfaces.dto.SystemDictQueryResultDTO;
import com.xinruke.hostels.system.manage.interfaces.api.SystemManageApi;
import com.xinruke.hostels.system.manage.interfaces.dto.RoomStatusColorAddDefaultDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import tk.mybatis.mapper.entity.Example;
import tk.mybatis.mapper.util.Sqls;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.*;
import java.util.stream.Collectors;

/**
 * @author GuoZheng
 * @ClassName HotelInfoServiceImpl
 * @date：2019/6/18
 * @version: V1.0.0
 * @description： 酒店信息service
 */
@Service
@Slf4j
public class HotelInfoService {
    @Resource
    private YwJiudianMapper ywJiudianMapper;
    @Resource
    private YwJiudianMeetingMapper ywJiudianMeetingMapper;

    @Resource
    private ManageUserApi manageUserApi;

    @Autowired
    SystemManageApi systemManageApi;

    @Resource
    private DictInfoCacheExtractor dictInfoCacheExtractor;

    @Resource
    private ManageUserCache manageUserCache;

    @Value("${hotel.jiudian.qitafuwu}")
    private String hotelJiudianQitafuwu;

    public HotelInfoDetailQueryResultDTO getHotelInfoDtail(HotelInfoDetailQueryDTO hotelDetailQueryDTO) {
        YwJiudian ywjiudian = ywJiudianMapper.selectByPrimaryKey(hotelDetailQueryDTO.getId());
        HotelInfoDetailQueryResultDTO resultDTO = new HotelInfoDetailQueryResultDTO();
        BeanUtils.copyProperties(ywjiudian, resultDTO);
        return resultDTO;
    }


    @Transactional
    public ResultVO addHotelInfo(HotelInfoAddDTO hotelInfoAddDTO) {
        //1.检查是否可以添加
        checkIsCanAdd(hotelInfoAddDTO);
        //2.插入酒店
        YwJiudian ywjiudian = new YwJiudian();
        BeanUtils.copyProperties(hotelInfoAddDTO, ywjiudian);
        ywjiudian.setShanchubiaoshi(SysDicConstant.DELFLAG_0);

        ywjiudian.setChuangjianrenId(manageUserCache.getCurrentUserId());
        ywjiudian.setChuangjianshijian(new Date());
        ywjiudian.setGengxinrenId(manageUserCache.getCurrentUserId());
        ywjiudian.setGengxinshijian(new Date());

        // 生成编码
        String bianma = createBianma(hotelInfoAddDTO.getDishi(), hotelInfoAddDTO.getXian());
        ywjiudian.setBianma(bianma);
        int i = ywJiudianMapper.insert(ywjiudian);
        if (i < 1) {
            throw new ArgumentException("插入酒店失败");
        }

        //通过酒店编码和酒店id初始化管理员
        String userNameAndPassword = ywjiudian.getBianma() + "_admin";

        UserInfoAddDefaultDTO userInfoAddDTO = new UserInfoAddDefaultDTO();
        userInfoAddDTO.setYonghuleixing(XtYewuyonghu.YONGHULEIXNG_CHANOGUAN);
        userInfoAddDTO.setSuoshuxitong(XtYewuyonghu.SUOSHUXITONG_PMS);
        userInfoAddDTO.setBeizhu("系统初始化用户");
        userInfoAddDTO.setYonghuming(userNameAndPassword);
        userInfoAddDTO.setJiudianId(ywjiudian.getId());
        userInfoAddDTO.setCurrentUserId(manageUserCache.getCurrentUserId());

        userNameAndPassword = MD5Util.md5(userNameAndPassword);
        userInfoAddDTO.setMima(userNameAndPassword);

        ResultVO resultVO = manageUserApi.addHotelUserInfo(userInfoAddDTO);
        if (resultVO.getCode() != ResultVO.SUCCESS) {
            throw new ServerException("初始化管理员失败，" + resultVO.getMessage());
        }

        //初始化房态颜色
        RoomStatusColorAddDefaultDTO roomStatusColorAddDefaultDTO = new RoomStatusColorAddDefaultDTO();
        roomStatusColorAddDefaultDTO.setJiudianId(ywjiudian.getId());
        ResultVO addDefaultResultVO = systemManageApi.addDefault(roomStatusColorAddDefaultDTO);
        if (addDefaultResultVO.getCode() != ResultVO.SUCCESS) {
            throw new ServerException("初始化房态颜色失败，" + addDefaultResultVO.getMessage());
        }

        return ResultVO.success();
    }

    /**
     * 生成酒店编码(8位数字码)，2种规则:1.省、市+00+2位序列号;2.省、市、县+2位序列号;
     */
    private String createBianma(String dishi, String xian) {
        String lastBianma;
        if (StringUtil.isBlank(xian)) {
            lastBianma = ywJiudianMapper.getLastBianmaByDishi(dishi);
            if (StringUtil.isBlank(lastBianma)) {
                lastBianma = dishi + "0000";
            }
        } else {
            lastBianma = ywJiudianMapper.getLastBianmaByXian(xian);
            if (StringUtil.isBlank(lastBianma)) {
                lastBianma = xian + "00";
            }
        }
        lastBianma = String.valueOf(Long.valueOf(lastBianma) + 1);
        return lastBianma;
    }

    public ResultVO modifyHotelInfo(HotelInfoModifyDTO hotelInfoModifyDTO) {
        //1.检查是否可以添加
        checkIsCanAdd(hotelInfoModifyDTO);
        //2.插入酒店
        YwJiudian ywjiudian = new YwJiudian();
        BeanUtils.copyProperties(hotelInfoModifyDTO, ywjiudian);

        ywjiudian.setGengxinrenId(manageUserCache.getCurrentUserId());
        ywjiudian.setGengxinshijian(new Date());

        int i = ywJiudianMapper.updateByPrimaryKeySelective(ywjiudian);
        if (i < 1) {
            throw new ArgumentException("更新酒店失败");
        }
        //通过酒店编码和酒店id初始化管理员
        return ResultVO.success();
    }

    private void checkIsCanAdd(HotelInfoModifyDTO hotelInfoModifyDTO) {
//        if (!StringUtils.isEmpty(hotelInfoModifyDTO.getBianma())) {
//            List<YwJiudian> ywJiudians = ywJiudianMapper.selectByExample(Example.builder(YwJiudian.class)
//                    .where(Sqls.custom().andEqualTo("shanchubiaoshi", SysDicConstant.DELFLAG_0)
//                            .andEqualTo("bianma", hotelInfoModifyDTO.getBianma())
//                            .andNotEqualTo("id", hotelInfoModifyDTO.getId())
//                    ).build());
//            //1. 业务编码已存在
//            if (!CollectionUtils.isEmpty(ywJiudians)) {
//                throw new ExistException("业务编码已存在");
//            }
//        }

    }

    public ResultVO delHotel(HotelInfoDelDTO hotelInfoDelDTO) {
        YwJiudian ywjiudian = new YwJiudian();
        BeanUtils.copyProperties(hotelInfoDelDTO, ywjiudian);
        ywjiudian.setShanchubiaoshi(SysDicConstant.DELFLAG_1);
        ywjiudian.setGengxinrenId(manageUserCache.getCurrentUserId());
        ywjiudian.setGengxinshijian(new Date());

        int i = ywJiudianMapper.updateByPrimaryKeySelective(ywjiudian);
        if (i < 1) {
            throw new ArgumentException("更新酒店失败");
        }
        return ResultVO.success();
    }

    /**
     * 检查是否可以添加酒店
     *
     * @param hotelInfoAddDTO
     */
    private void checkIsCanAdd(HotelInfoAddDTO hotelInfoAddDTO) {

//        List<YwJiudian> ywJiudians = ywJiudianMapper.selectByExample(Example.builder(YwJiudian.class)
//                .where(Sqls.custom().andEqualTo("shanchubiaoshi", SysDicConstant.DELFLAG_0)
//                        .andEqualTo("bianma", hotelInfoAddDTO.getBianma())
//                ).build());
//        //1. 业务编码已存在
//        if (!CollectionUtils.isEmpty(ywJiudians)) {
//            throw new ExistException("业务编码已存在");
//        }

    }

    public ResultVO<RowsDataVO<HotelCentralQueryResultDTO>> getPMSHotelList(HotelPMSQueryDTO pmsQueryDTO) {

        RowsDataVO<HotelCentralQueryResultDTO> rowsDataVO = new RowsDataVO<>();
        Integer jiudianId = manageUserCache.getJiudianId();
        //酒店查询条件
        QueryConditions conditions = new QueryConditions();
        conditions.addCondition("shanchubiaoshi", EConditionOperator.EQULS, SysDicConstant.DELFLAG_0);
        conditions.addCondition("id", EConditionOperator.EQULS, jiudianId);
        MyExample example = new MyExample(YwJiudian.class, conditions, pmsQueryDTO.getOrderFields());
        Page<HotelPersonalQueryResultDTO> page = PageHelper.startPage(pmsQueryDTO.getPageNo(), pmsQueryDTO.getPageSize());
        List<YwJiudian> ywjiudianList = ywJiudianMapper.selectByExample(example);

        //组装结果
        List<HotelCentralQueryResultDTO> resultDTOS = ywjiudianList.stream().map(ywJiudian -> {
            HotelCentralQueryResultDTO resultDTO = new HotelCentralQueryResultDTO();
            BeanUtils.copyProperties(ywJiudian, resultDTO);
            resultDTO.setDishiMingcheng(ywJiudian.getDishi());
            resultDTO.setShengfenMingchegn(ywJiudian.getShengfen());
            resultDTO.setXianMingcheng(ywJiudian.getXian());
            resultDTO.setXingjiMingcheng(dictInfoCacheExtractor.getDictValue(SysDicConstant.XINGJI, ywJiudian.getXingji()));
            return resultDTO;
        }).collect(Collectors.toList());

        rowsDataVO.setPageNo(page.getPageNum());
        rowsDataVO.setTotalPages(page.getPages());
        rowsDataVO.setTotalRecords(page.getTotal());
        rowsDataVO.setRows(resultDTOS);

        ResultVO<RowsDataVO<HotelCentralQueryResultDTO>> resultVO = ResultVO.success();
        resultVO.setData(rowsDataVO);
        return resultVO;
    }

    public List<YwJiudian> getAllHotel(HotelAllQueryDTO allQueryDTO) {
        return ywJiudianMapper.selectByExample(Example.builder(YwJiudian.class)
                .where(Sqls.custom().andEqualTo("shanchubiaoshi", SysDicConstant.DELFLAG_0))
                .build());
    }

    /**
     * 获取个人酒店信息集合
     *
     * @param params
     * @return
     */
    public RowsDataVO<HotelPersonalQueryResultDTO> getPersonalHotelInfoList(HotelPersonalQueryDTO params) {
        RowsDataVO<HotelPersonalQueryResultDTO> dataVO = new RowsDataVO();


        Map hotelParamMap = new HashMap();
        hotelParamMap.put("nameOrAddress", params.getNameOrAddress());
        hotelParamMap.put("roomCount", params.getRoomCount());
        hotelParamMap.put("minRoomPrice", params.getMinRoomPrice());
        hotelParamMap.put("maxRoomPrice", params.getMaxRoomPrice());
        hotelParamMap.put("roomType", params.getRoomType());
        hotelParamMap.put("averageScore", params.getAverageScore());
        hotelParamMap.put("xingji", params.getXingji());
        hotelParamMap.put("startTime", params.getStartTime());
        hotelParamMap.put("endTime", params.getEndTime());
        hotelParamMap.put("shengfen", params.getShengfen());
        hotelParamMap.put("dishi", params.getDishi());
        hotelParamMap.put("xian", params.getXian());

        List<String> qitafuwuList = params.getQitafuwu();
        if (!CollectionUtils.isEmpty(qitafuwuList)) {
            String qitafuwus = "";
            for (String fuwu : qitafuwuList) {
                qitafuwus = qitafuwus + fuwu + ",";
            }
            if (qitafuwus.endsWith(",")) {
                hotelParamMap.put("qitafuwu", qitafuwus.substring(0, qitafuwus.length() - 1));
            }
        }

        List<OrderField> orderFieldList = params.getOrderFields();
        if (!CollectionUtils.isEmpty(orderFieldList)) {
            String orderStr = "";
            for (OrderField orderField : orderFieldList) {
                if (!StringUtils.isEmpty(orderStr)) {
                    orderStr = orderStr + ",";
                }
                if ("averageScore".equals(orderField.getOrderField())) {
                    if (orderField.getOrderDesc()) {
                        orderStr = orderStr + "averageScore desc";
                    } else {
                        orderStr = orderStr + "averageScore";
                    }
                } else if ("maxmendianjia".equals(orderField.getOrderField())) {
                    if (orderField.getOrderDesc()) {
                        orderStr = orderStr + "maxmendianjia desc";
                    } else {
                        orderStr = orderStr + "maxmendianjia";
                    }
                } else if ("minmendianjia".equals(orderField.getOrderField())) {
                    if (orderField.getOrderDesc()) {
                        orderStr = orderStr + "minmendianjia desc";
                    } else {
                        orderStr = orderStr + "minmendianjia";
                    }
                }
            }
            if (!StringUtils.isEmpty(orderStr)) {
                orderStr = "order by " + orderStr;
            }
            hotelParamMap.put("orderStr", orderStr);

        }
        Page page = PageHelper.startPage(params.getPageNo(), params.getPageSize());
        List<HotelPersonalQueryResultDTO> resultDTOList = ywJiudianMapper.selectHotelList(hotelParamMap);

        for (HotelPersonalQueryResultDTO hotelQueryResultDTO : resultDTOList) {
            int hotelId = hotelQueryResultDTO.getId();

            //处理酒店的会议室、餐厅
            Map paramMap = new HashMap();
            paramMap.put("hotelId", hotelId);
            paramMap.put("startTime", params.getStartTime());
            paramMap.put("endTime", params.getEndTime());
            List<Map<String, Object>> hotelMeetingCountList = ywJiudianMapper.selectHotelMeetingCountList(paramMap);
            if (!CollectionUtils.isEmpty(hotelMeetingCountList) && hotelMeetingCountList.size() == 1) {
                Map<String, Object> hotelMeetingCountMap = hotelMeetingCountList.get(0);

                if (hotelMeetingCountMap.get("meetingCount") != null) {
                    int meetingCount = Integer.parseInt(hotelMeetingCountMap.get("meetingCount").toString());
                    hotelQueryResultDTO.setMeetingCount(meetingCount);
                }
                if (hotelMeetingCountMap.get("restaurantCount") != null) {
                    int restaurantCount = Integer.parseInt(hotelMeetingCountMap.get("restaurantCount").toString());
                    hotelQueryResultDTO.setRestaurantCount(restaurantCount);
                }
            }

            //转义其他服务
            List<QitafuwuShowInfoDTO> qitafuwulist = new ArrayList<>();
            String qitafuwu = hotelQueryResultDTO.getQitafuwu();
            if (!StringUtils.isEmpty(qitafuwu)) {
                String[] qitafuwus = hotelQueryResultDTO.getQitafuwu().split(",");
                for (String fuwu : qitafuwus) {
                    if (StringUtils.isEmpty(hotelJiudianQitafuwu)) {
                        break;
                    }
                    if (("," + hotelJiudianQitafuwu + ",").contains("," + fuwu + ",")) {
                        SystemDictQueryResultDTO systemDictQueryResultDTO = dictInfoCacheExtractor.getSystemDictQueryResultDTO("cm.qitafuwu", fuwu);
                        QitafuwuShowInfoDTO qitafuwuShowInfoDTO = new QitafuwuShowInfoDTO();
                        qitafuwuShowInfoDTO.setQitafuwuicon(systemDictQueryResultDTO.getMiaoshu());
                        qitafuwuShowInfoDTO.setQitafuwumingcheng(systemDictQueryResultDTO.getCanshumingcheng());
                        qitafuwulist.add(qitafuwuShowInfoDTO);
                    }
                }
            }
            hotelQueryResultDTO.setQitafuwushowinfo(qitafuwulist);

            //转义评分
            hotelQueryResultDTO.setAverageScoreMingcheng(ECommentScoreDescribe.getDescribeByScore(hotelQueryResultDTO.getAverageScore()));
        }

        dataVO.setPageNo(page.getPageNum());
        dataVO.setTotalRecords(page.getTotal());
        dataVO.setTotalPages(page.getPages());
        dataVO.setRows(resultDTOList);
        return dataVO;

    }

    /**
     * 获取会议酒店信息集合
     *
     * @param params
     * @return
     */
    public RowsDataVO<HotelMeetingQueryResultDTO> getMeetingHotelInfoList(HotelMeetingQueryDTO params) {
        RowsDataVO<HotelMeetingQueryResultDTO> rowsDataVO = new RowsDataVO();
        List<HotelMeetingQueryResultDTO> hotelMeetingQueryResultDTOList = new ArrayList<>();

        Map hotelParamMap = new HashMap();
        hotelParamMap.put("nameOrAddress", params.getNameOrAddress());
        hotelParamMap.put("startTime", params.getStartTime());
        hotelParamMap.put("endTime", params.getEndTime());
        hotelParamMap.put("meetingCount", params.getMeetingCount());
        hotelParamMap.put("huiyijibie", params.getHuiyijibie());
        hotelParamMap.put("minNumberOfPeople", params.getMinNumberOfPeople());
        hotelParamMap.put("maxNumberOfPeople", params.getMaxNumberOfPeople());
        hotelParamMap.put("shengfen", params.getShengfen());
        hotelParamMap.put("dishi", params.getDishi());
        hotelParamMap.put("xian", params.getXian());
        hotelParamMap.put("danrenjianCount", params.getDanrenjianCount());
        hotelParamMap.put("biaozhunCount", params.getBiaozhunCount());
        hotelParamMap.put("duorenjianCount", params.getDuorenjianCount());
        hotelParamMap.put("taojianCount", params.getTaojianCount());

        List<OrderField> orderFieldList = params.getOrderFields();
        if (!CollectionUtils.isEmpty(orderFieldList)) {
            String orderStr = "";
            for (OrderField orderField : orderFieldList) {
                if (!StringUtils.isEmpty(orderStr)) {
                    orderStr = orderStr + ",";
                }
                if ("averageScore".equals(orderField.getOrderField())) {
                    if (orderField.getOrderDesc()) {
                        orderStr = orderStr + "averageScore desc";
                    } else {
                        orderStr = orderStr + "averageScore";
                    }
                } else if ("maxmendianjia".equals(orderField.getOrderField())) {
                    if (orderField.getOrderDesc()) {
                        orderStr = orderStr + "maxmendianjia desc";
                    } else {
                        orderStr = orderStr + "maxmendianjia";
                    }
                } else if ("minmendianjia".equals(orderField.getOrderField())) {
                    if (orderField.getOrderDesc()) {
                        orderStr = orderStr + "minmendianjia desc";
                    } else {
                        orderStr = orderStr + "minmendianjia";
                    }
                }
            }
            if (!StringUtils.isEmpty(orderStr)) {
                orderStr = "order by " + orderStr;
            }
            hotelParamMap.put("orderStr", orderStr);

        }
        Page page = PageHelper.startPage(params.getPageNo(), params.getPageSize());
        List<HotelMeetingQueryResultDTO> hotelMeetingList = ywJiudianMeetingMapper.selectHotelMeetingList(hotelParamMap);

        hotelMeetingList.stream().forEach(m -> {
            HotelMeetingQueryResultDTO hotelMeetingQueryResultDTO = new HotelMeetingQueryResultDTO();
            BeanUtils.copyProperties(m, hotelMeetingQueryResultDTO);

            int hotelId = m.getId();
            Map paramMap = new HashMap();
            paramMap.put("hotelId", hotelId);
            paramMap.put("startTime", params.getStartTime());
            paramMap.put("endTime", params.getEndTime());

            //处理酒店的会议室、餐厅
            List<Map<String, Object>> hotelMeetingCountList = ywJiudianMeetingMapper.selectHotelMeetingCountList(paramMap);
            if (!CollectionUtils.isEmpty(hotelMeetingCountList) && hotelMeetingCountList.size() == 1) {
                Map<String, Object> hotelMeetingCountMap = hotelMeetingCountList.get(0);

                if (hotelMeetingCountMap.get("huiyijiage") != null) {
                    double huiyijiage = Double.parseDouble(hotelMeetingCountMap.get("huiyijiage").toString());
                    hotelMeetingQueryResultDTO.setHuiyijiage(new BigDecimal(huiyijiage));
                }
                if (hotelMeetingCountMap.get("meetingCount") != null) {
                    int meetingCount = Integer.parseInt(hotelMeetingCountMap.get("meetingCount").toString());
                    hotelMeetingQueryResultDTO.setMeetingCount(meetingCount);
                }
                if (hotelMeetingCountMap.get("restaurantCount") != null) {
                    int restaurantCount = Integer.parseInt(hotelMeetingCountMap.get("restaurantCount").toString());
                    hotelMeetingQueryResultDTO.setRestaurantCount(restaurantCount);
                }
            }

            //循环处理不同类型的房间数量
            List<Map<String, Object>> hotelRoomCountList = ywJiudianMeetingMapper.selectHotelRoomCountList(paramMap);
            int roomCountSum = 0;
            for (Map<String, Object> hotelRoomCount : hotelRoomCountList) {
                if (hotelRoomCount.get("type") == null || hotelRoomCount.get("roomCount") == null || hotelRoomCount.get("jiage") == null) {
                    continue;
                }
                double jiage = Double.parseDouble(hotelRoomCount.get("jiage").toString());
                hotelMeetingQueryResultDTO.setJiage(new BigDecimal(jiage));

                int type = Integer.parseInt(hotelRoomCount.get("type").toString());
                int roomCount = Integer.parseInt(hotelRoomCount.get("roomCount").toString());
                if (type == YwFangjianLeixingConstants.TYPE_DANRENJIAN) {
                    hotelMeetingQueryResultDTO.setDanrenjianCount(roomCount);
                } else if (type == YwFangjianLeixingConstants.TYPE_BIAOZHUNJIAN) {
                    hotelMeetingQueryResultDTO.setBiaozhunCount(roomCount);
                } else if (type == YwFangjianLeixingConstants.TYPE_DUORENJIAN) {
                    hotelMeetingQueryResultDTO.setDuorenjianCount(roomCount);
                } else if (type == YwFangjianLeixingConstants.TYPE_TAOJIAN) {
                    hotelMeetingQueryResultDTO.setTaojianCount(roomCount);
                }
                roomCountSum = roomCountSum + roomCount;
            }
            hotelMeetingQueryResultDTO.setRoomCount(roomCountSum);

            hotelMeetingQueryResultDTOList.add(hotelMeetingQueryResultDTO);
        });

        rowsDataVO.setPageNo(page.getPageNum());
        rowsDataVO.setTotalRecords(page.getTotal());
        rowsDataVO.setTotalPages(page.getPages());
        rowsDataVO.setRows(hotelMeetingQueryResultDTOList);
        return rowsDataVO;
    }

    public ResultVO<RowsDataVO<HotelCentralQueryResultDTO>> getHotelCentralInfoList(HotelCentralQueryDTO hotelCentralQueryDTO) {
        RowsDataVO<HotelCentralQueryResultDTO> rowsDataVO = new RowsDataVO<>();
        //酒店查询条件
        QueryConditions conditions = new QueryConditions();
        conditions.addCondition("mingcheng", EConditionOperator.LIKE, hotelCentralQueryDTO.getMingcheng());
        conditions.addCondition("shanchubiaoshi", EConditionOperator.EQULS, SysDicConstant.DELFLAG_0);
        MyExample example = new MyExample(YwJiudian.class, conditions, hotelCentralQueryDTO.getOrderFields());
        Page<HotelPersonalQueryResultDTO> page = PageHelper.startPage(hotelCentralQueryDTO.getPageNo(), hotelCentralQueryDTO.getPageSize());
        List<YwJiudian> ywjiudianList = ywJiudianMapper.selectByExample(example);

        //组装结果
        List<HotelCentralQueryResultDTO> resultDTOS = ywjiudianList.stream().map(ywJiudian -> {
            HotelCentralQueryResultDTO resultDTO = new HotelCentralQueryResultDTO();
            BeanUtils.copyProperties(ywJiudian, resultDTO);
            resultDTO.setShengfenMingchegn(ywJiudian.getShengfen());
            resultDTO.setDishiMingcheng(ywJiudian.getDishi());
            resultDTO.setXianMingcheng(ywJiudian.getXian());
            resultDTO.setXingjiMingcheng(dictInfoCacheExtractor.getDictValue(SysDicConstant.XINGJI, ywJiudian.getXingji()));
            return resultDTO;
        }).collect(Collectors.toList());

        rowsDataVO.setPageNo(page.getPageNum());
        rowsDataVO.setTotalRecords(page.getTotal());
        rowsDataVO.setTotalPages(page.getPages());
        rowsDataVO.setRows(resultDTOS);

        ResultVO<RowsDataVO<HotelCentralQueryResultDTO>> resultVO = ResultVO.success();
        resultVO.setData(rowsDataVO);
        return resultVO;
    }

    /**
     * 下拉框酒店列表
     *
     * @param allQueryDTO
     * @return
     */
    public ResultVO<List<HotelAllQueryResultDto>> getAllHotelList(HotelAllQueryDTO allQueryDTO) {
        ResultVO<List<HotelAllQueryResultDto>> resultVO = ResultVO.success();

        List<YwJiudian> allHotel = ywJiudianMapper.selectByExample(Example.builder(YwJiudian.class)
                .where(Sqls.custom().andEqualTo("shanchubiaoshi", SysDicConstant.DELFLAG_0))
                .build());
        List<HotelAllQueryResultDto> resultDTOList = allHotel.stream().map(h -> {
            HotelAllQueryResultDto dto = new HotelAllQueryResultDto();
            BeanUtils.copyProperties(h, dto);
            return dto;
        }).collect(Collectors.toList());

        resultVO.setData(resultDTOList);
        return resultVO;
    }

}
